import { Moment } from 'moment';

export const formatToDate = (date: string) => {
  if (!date) {
    return;
  }
  let pattern = /(\d{4})-(\d{2})-(\d{2})\s(\d{2}):(\d{2}):(\d{2})/;
  date.replace(pattern, '$1/$2/$3 $4:$5:$6');
  return new Date(date);
};

export const convertRangeDate = (key: string, moments: Moment[]): any => {
  let param = {};

  if (moments.length < 2) {
    return param;
  }
  param[key] = [moments[0].toDate(), moments[1].toDate()];
  return param;
};
